package ys.com;

import java.io.*;
import java.net.Socket;

/**
 * @ClassName TestStock
 * @DeScription TODO
 * @Author 剧情再美终是戏
 * @Date 2019/10/9 23:06
 * @Version 1.0
 **/
public class TestStock {

    public static void main(String[] args) throws Exception {

        Socket socket = new Socket("127.0.0.1", 8080);
        OutputStream outputStream = socket.getOutputStream();

        // HTTP请求
        PrintWriter printWriter = new PrintWriter(outputStream, true);
        printWriter.println("GET / HTTP/1.1");
        printWriter.println("Host:127.0.0.1:8080");
        printWriter.println("Connection:Close");
        printWriter.println();

        System.out.println("go");

        // HTTP响应
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        StringBuffer stringBuffer = new StringBuffer(8096);
        boolean loop = true;
        while (loop) {
            if(in.ready()) {
                int i =0;
                while (i!=-1) {
                    i=in.read();
                    stringBuffer.append((char)i);
                }
                loop = false;
            }
            Thread.sleep(50);
        }

        System.out.println(stringBuffer.toString());
        socket.close();
    }
}
